import React, { Component } from "react";
// 组件
import MainLayout from "../../../component/mainLayout/mainLayout";
import { Button, Toast } from "antd-mobile";
import Card from "../bankList/card.jsx";

import yhTools from "../../../tools/yh";
import XHQBConfig from "../../../config/XHQBConfig";
import "./unboundBankCard.scss";

/**
 * 描述：
 * 作者：zenghq
 * 日期：2020-06-11
 */
class unboundBankCard extends Component {
	constructor(props) {
		super(props);
		this.state = {
			bankCardInfo: {}
		};
		this.bankCardId = ""; // 会员绑卡编号
	}
	/*******************生命周期 start************************/
	componentDidMount = () => {
		const { state = {} } = this.props.location;
		const { bankCardInfo = {} } = state;
		this.bankCardId = bankCardInfo.bankCardId;
		this.setState({
			bankCardInfo
		});
	};
	componentWillUnmount = () => {};
	/*******************生命周期 end************************/

	/*******************业务方法 start************************/
	/*******************业务方法 end************************/

	/*******************点击事件 start************************/
	handleUnboundBank() {
		Toast.loading("加载中...", 10);
		let objs = {
			url: XHQBConfig.confirmUnbind,
			params: {
				bankCardId: this.bankCardId
			},
			_alertShow: false
		};
		yhTools.request(objs).then(res => {
			Toast.hide();
			if (res.code === "0") {
				Toast.info("解绑成功", 2);
				setTimeout(() => {
					this.props.history.goBack();
				}, 2000);
			} else {
				Toast.info(res.message, 2);
			}
		});
	}
	/*******************点击事件 end************************/

	/**渲染 */
	render() {
		const { bankCardInfo } = this.state;
		const _pageParams = {
			header: {
				title: "解绑银行卡"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};
		return (
			<MainLayout pageParams={_pageParams}>
				<div className="unbound-box">
					<div className="bank_card-box">
						<Card item={bankCardInfo} key={Math.random()} />
					</div>

					<Button
						className="unbound_btn"
						onClick={this.handleUnboundBank.bind(this)}
					>
						解除绑定银行卡
					</Button>
				</div>
			</MainLayout>
		);
	}
}

export default unboundBankCard;
